package com.yunfeisoft.business.dao.impl.postgres;

import com.applet.base.ServiceDaoImpl;
import com.applet.sql.builder.SelectBuilder;
import com.applet.sql.builder.WhereBuilder;
import com.applet.utils.Page;
import com.yunfeisoft.business.dao.inter.CmsSubjectDao;
import com.yunfeisoft.business.model.CmsSubject;
import com.yunfeisoft.business.model.CmsSubjectCategory;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * ClassName: CmsSubjectDaoImpl
 * Description: 专题表Dao实现
 * Author: Jackie liu
 * Date: 2020-06-02
 */
@Repository
public class CmsSubjectDaoImpl extends ServiceDaoImpl<CmsSubject, String> implements CmsSubjectDao {

    @Override
    public Page<CmsSubject> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
            wb.andFullLike("s.title", params.get("title"));
        }
        SelectBuilder builder = getSelectBuilder("s");
        builder.column("sc.name as categoryName")
                .join(CmsSubjectCategory.class).alias("sc").on("s.categoryId = sc.id").build();

        return queryPage(builder.getSql(), wb);
    }
}